package Validaciones;

import com.toedter.calendar.JTextFieldDateEditor;
import javax.swing.*;

public class ValidacionesAccidentes {

    public static boolean validaTipo(int seleccion) {
        if (seleccion == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean validaSeleccion(String seleccion, JTextField campo) {
        if (seleccion.equals("")) {
            pintar(campo);
            return true;
        } else {
            return false;
        }
    }

    public static boolean validaLugar(String texto, JTextField campo) {
        if (texto.equals("") || !texto.matches("^[A-Za-zñÑáéíóúÁÉÍÓÚ\\.,0-9(\\s)?]{4,45}$")) {
            pintar(campo);
            return true;
        } else {
            campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }
    }

    public static boolean validaCalendario(String seleccion, JTextFieldDateEditor fec) {
        if (seleccion.equals("")) {
            ((JTextFieldDateEditor) fec).setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
            return true;
        }
        ((JTextFieldDateEditor) fec).setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
        return false;
        
    }

    public static boolean validaLesionados(String texto, JTextField campo) {
	        try {
	            int numero = Integer.parseInt(texto);
	            if (numero > 99) {
	                pintar(campo);
	                return true;
	            }
                    campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
	            return false;
	        } catch (Exception e) {
	            pintar(campo);
	            return true;
	        }
    }    
    
    public static boolean validaVacio(String texto, JTextField campo) {
        if (texto.equals("")) {
            pintar(campo);
            return true;
        } else {
            campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }
    }
    public static boolean validaHora(String texto, JTextField campo) {
        String[] aux = texto.split(":");
        
        if (aux[0].equals("  ") || aux[1].equals("  ")) {
            pintar(campo);
            return true;
        } else {
            campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }
    }

    public static boolean validaHoras(int hora, int minuto, JTextField campo) {
        try {
            if (hora > 23 || hora <0 || minuto>59 || minuto<0) {
                pintar(campo);
                return true;
            } else {
                campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
                return false;
            }
        } catch (Exception e) {
            return true;
        }

    }
    public static boolean validaDesc(String desc, JButton boton) {
        
            if (desc.equals("")) {
                boton.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
                return true;
            } else {
                boton.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
                return false;
            }
    }
    public static void pintarNegro(JComponent campo){
        campo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    }
    
    public static void pintar(JTextField txt) {
        txt.requestFocus();
        txt.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));        
        txt.setSelectionStart(0);
        txt.setSelectionEnd(txt.getText().length());
    }
    public static void pintarVerde(JTextField txt) {
        txt.requestFocus();
        txt.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
        txt.setSelectionStart(0);
        txt.setSelectionEnd(txt.getText().length());
    }
}
